﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;

namespace System.ComponentModel.Composition
{
    /// <summary>
    ///     Specifies required metadata for a property, field or parameter marked with the
    ///     <see cref="ImportAttribute"/>.
    /// </summary>
    /// <remarks>
    ///     By default, any export that matches the contract name of an import will be considered a
    ///     match for that import. Use this attribute to indicate that an export should also contain 
    ///     specific metadata to be considered a match.
    /// </remarks>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
                    AllowMultiple = true, Inherited = true)]
    public sealed class ImportRequiredMetadataAttribute : Attribute
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="ImportRequiredMetadataAttribute"/> class
        ///     with the specified required metadata name.
        /// </summary>
        /// <param name="name">
        ///     A <see cref="String"/> containing the name of the required metadata value, or 
        ///     <see langword="null"/> to use an empty string ("").
        /// </param>
        public ImportRequiredMetadataAttribute(string name)
        {
            this.Name = name ?? string.Empty;
        }

        /// <summary>
        ///     Gets the name of the required metadata value.
        /// </summary>
        /// <value>
        ///     A <see cref="String"/> containing the name of the required metadata value.
        /// </value>
        public string Name
        {
            get;
            private set;
        }
    }
}
